<?php

namespace app\api\model\cps;

require_once ROOT_PATH.'extend/ali-sdk/TopSdk.php';
require_once ROOT_PATH.'extend/ali-sdk/top/TopClient.php';
require_once ROOT_PATH.'extend/ali-sdk/top/request/AlibabaAlscUnionElemeStorepromotionReviewbwcQueryRequest.php';
require_once ROOT_PATH.'extend/ali-sdk/top/request/AlibabaAlscUnionElemeStorepromotionReviewbwcStockLockRequest.php';
require_once ROOT_PATH.'extend/ali-sdk/top/request/AlibabaAlscUnionElemeStorepromotionReviewbwcStockReleaseRequest.php';


class ElmMeal
{
    protected $appkey = '34748608';

    protected $secret = '5971095b9c2c9ace757cd60b82d78b1c';

    protected $pid = 'alsc_27756062_8185001_21287100';

    public function shoplist($search,$lat,$lng,$sort_type)
    {

        $c = new \TopClient();
        $c->appkey = $this->appkey;
        $c->secretKey = $this->secret;
        $req = new \AlibabaAlscUnionElemeStorepromotionReviewbwcQueryRequest;
        $req->setPid($this->pid);
        $req->setLongitude($lng);
        $req->setLatitude($lat);
        $req->setSortType($sort_type);
        if ($search)$req->setSearchContent($search);
        $req->setExcludeLink("true");
        $resp = $c->execute($req);

        return $resp;
    }


    //霸王餐库存锁定
    public function stocklock($shop_id,$activity_id,$mobile,$order_id)
    {
        $c = new \TopClient();
        $c->appkey = $this->appkey;
        $c->secretKey = $this->secret;
        $req = new \AlibabaAlscUnionElemeStorepromotionReviewbwcStockLockRequest;
        $req->setPid($this->pid);
        $req->setShopId($shop_id);//门店ID（加密）
        $req->setActivityId($activity_id);//活动ID
        $req->setMobile($mobile);//领取手机号
        $req->setOuterOrderId($order_id);//	领取ID（渠道用户领取资格的唯一标识）
        $resp = $c->execute($req);
        return $resp;
    }

    //霸王餐库存释放
    public function stockrelease($lockid)
    {
        $c = new \TopClient();
        $c->appkey = $this->appkey;
        $c->secretKey = $this->secret;
        $req = new \AlibabaAlscUnionElemeStorepromotionReviewbwcStockReleaseRequest;
        $req->setLockId($lockid);//库存锁定ID
        $resp = $c->execute($req);
        return $resp;
    }
}